﻿using AutoMapper;
using Domain.Entity;
using Domain.Entity.bs;
using Domain.Entity.sys;
using Domain.Entity.zct;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace Application.PublicFileService
{
    public class PublicFileService : IPublicFileService
    {   
        private readonly IPublicFileRepository publicFileRepository;
        private readonly IMapper mapper;

        public PublicFileService(IPublicFileRepository publicFileRepository,IMapper mapper)
        {
            this.publicFileRepository = publicFileRepository;
            this.mapper = mapper;
        }

        //添加附件
        public async Task<int> AddFile(string? type, string? code, string? file, string? title)
        {
            return await publicFileRepository.AddFile(type, code, file,title);
        }

        //添加附件
        public async Task<int> AddFile(AddFileDto addFileDto)
        {
            PublicFile publicFile=mapper.Map<PublicFile>(addFileDto);
            return await publicFileRepository.AddFile(publicFile);
        }

        //删除公共附件
        public async Task<int> DeleteFile(string? type, string? code)
        {
            return await publicFileRepository.DeleteFile(type, code);
        }

        //根据业务类型和编号查询对应的附件
        public async Task<List<PublicFile>> GetPublicFileBy(string? type, string? code)
        {
            return await publicFileRepository.GetPublicFileBy(type, code);
        }

    }
}
